package com.guonima;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 服务提供者类
 */
@EnableEurekaClient
@SpringBootApplication
@RestController
public class EurekaClientApplication {

	private final Logger logger = LoggerFactory.getLogger(this.getClass());

	public static void main(String[] args) {
		SpringApplication.run(EurekaClientApplication.class, args);
	}

	@Value("${server.port}")
	private String port;

	@Autowired
	private DiscoveryClient discoveryClient;

	@RequestMapping("/test")
	public String test(@RequestParam String name){
		logger.info("eureka-client has been call {}, call services name is {}", name, discoveryClient.getServices());

		return "hi, my name is " + name + ", i am a server provider; " + port
				+ "; call service name are " + discoveryClient.getServices();
	}
}
